#!/bin/sh

dotnet_runtime_snaps=$(ls "$SNAP/../.." | grep dotnet-runtime)

for snap in "$dotnet_runtime_snaps"
do
  runtime_dir=$(realpath "$SNAP/../../$snap/current/shared/Microsoft.NETCore.App")
  if [ -d "$runtime_dir" ]; then
    runtime_version=$(ls "$runtime_dir")
    runtime_path="$SNAP_DATA/Microsoft.NETCore.App/$runtime_version"
    if [ ! -d "$runtime_path" ]; then
      sudo ln -s "$runtime_dir/$runtime_version" "$runtime_path"
    fi
  fi
done

exec $SNAP/dotnet "$@"
